package cn.dslcode.security.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
           registry.addMapping("/**")
           .allowedOrigins("*")
           .allowedMethods(RequestMethod.POST.name())
           .allowCredentials(true)
           .maxAge(60 * 30);
    }

    @Autowired
    private CustomSecurityConstant securityConstant;

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("/").setViewName("index");
//        registry.addViewController(securityConstant.getUri().getLoginForm()).setViewName("login");
        registry.addViewController("/user/list/page").setViewName("userList");
        registry.addViewController("/user/edit/page").setViewName("userEdit");
        registry.addViewController("/user/authority/edit/page").setViewName("userAuthorityEdit");
        registry.addViewController(securityConstant.getUri().getUnauthorized()).setViewName("403");
    }

}